<template>
	<view class="police-news">
		<!-- 新闻列表 -->
		<view class="news-block">
		  <!-- 循环列表 -->
		  <block v-for="(v, index) in page.list" :key="index">
			  <view class="news-item flex" @tap="goDetail(v)">
				<image class="mainImg" mode="aspectFill" :src="v.img_url"></image>
				<view class="news">
				  <view class="title">{{v.title}}</view>
				  <!-- <view class="des" v-html="v.content.replace(/<img[^>]*>/gi, '')"></view> -->
				  <view class="time">{{v.create_time}}</view>
				</view>
			  </view>
		  </block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: {
					pageNumber: 1,
					firstPage: true,
					lastPage: true,
					list: [],
				},
				
				noMore: false,
				
				current: null,
				
			};
		},
		props: ['showNum'],
		onReachBottom(){
			console.log('触底');
			if(this.page.lastPage) {this.noMore = true;return;}
			this.getDataMore(++this.page.pageNumber);
		},
		methods:{
			getData(pageNumber){
				let self = this;
				uni.showLoading({title: '加载中',mask: true});
				this.config.post('/app/news/findPage', {
					pageNum: pageNumber?pageNumber:1,
				}).then(res=>{
					uni.hideLoading();
					if(res.data.code==='0'){
						self.page.pageNumber = res.data.page.pageNumber;
						self.page.firstPage = res.data.page.firstPage;
						self.page.lastPage = res.data.page.lastPage;
						self.page.list = res.data.page.list;
					}else{
						uni.showToast({title: self.config.handleError(res.data),icon: 'none'});
					}
				})
			},
			getDataMore(pageNumber){
				let self = this;
				uni.showLoading({title: '加载中',mask: true});
				this.config.post('/app/news/findPage', {
					pageNum: pageNumber?pageNumber:1,
					newsTypeId: 'eb8deecb-8de9-471e-affe-57f0525194d7',
				}).then(res=>{
					uni.hideLoading();
					if(res.data.code==='0'){
						self.page.pageNumber = res.data.page.pageNumber;
						self.page.firstPage = res.data.page.firstPage;
						self.page.lastPage = res.data.page.lastPage;
						self.page.list = self.page.list.concat(res.data.page.list);
					}else{
						uni.showToast({title: self.config.handleError(res.data),icon: 'none'});
					}
				})
			},
			goDetail(v){
				uni.navigateTo({
					url: '/pages/main/news-detail/news-detail?id='+v.id
				})
			},
			homeFun(){
				if(this.page.list.length) return;
				this.getData()
			}
		},
		onShow() {
			this.getData('1');
		},
		mounted() {
		},
	}
</script>

<style lang="less" scoped>
	/* 警务资讯 */
	.police-news{
	  margin: .5rem 0;
	  padding: 0 15upx;
	  // background: #fff;
	}
	.police-news .news-block .news-item{
	  padding: .5rem 1.3rem;
	  margin: 0 0 15upx;
	  background-color: #eee;
	  position: relative;
	  border-radius: 15upx;
	  box-shadow: -3upx 3upx 10upx 0 #C0C0C0;
	}
	.police-news .news-block .news-item .mainImg{
	  width: 80px; height: 70px; background-color: #eeeeee;
	  margin-right: .8rem;
	}
	.police-news .news-block .news-item .news{
	  width: 80%;
	  display: flex;
	  flex-direction: column;
	  justify-content: space-between;
	}
	.police-news .news-block .news-item .news .title{
	  font-size: .9rem;
	  line-height: 50upx;
	  color: #333;
	  
	  display: -webkit-box;
	  -webkit-box-orient: vertical;
	  -webkit-line-clamp: 2;
	  overflow: hidden;
	}
	.police-news .news-block .news-item .news .des{
		font-size: .8rem;
		line-height: 40upx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	.police-news .news-block .news-item .news .time{
		font-size: .8rem;
		// color: #6a6a6b;
		color: #999;
	}
</style>
